﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Data;
using System.Web.Script.Serialization;

namespace EWMSWeb.ashx
{
    /// <summary>
    /// pageJuqery 的摘要说明
    /// </summary>
    public class pageJuqery : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string iSortCol_0 = "";
            string sSortDir_0 = "";
            if (context.Request["iSortCol_0"] != null && context.Request["iSortCol_0"].ToString().Trim() != "")
            {
                iSortCol_0 = context.Request["iSortCol_0"].Trim();
                sSortDir_0 = context.Request["sSortDir_0"].Trim();
            }


            context.Response.ContentType = "text/plain";
            string json = "";

            string sEcho = "";
            int currpage = 0;
            int length = 0;
            string gcity = "";
            string bcity = "";
            string search = "";
            string uname = "";

            if (context.Request["pagetype"] != null)
            {
                string pagetype = context.Request["pagetype"].ToString().Trim();
                sEcho = context.Request["sEcho"];
                currpage = int.Parse(context.Request["iDisplayStart"]);
                length = int.Parse(context.Request["iDisplayLength"]);
                search = context.Request["sSearch"];


                switch (pagetype)
                {
                    case "im":
                        gcity = HttpUtility.UrlDecode(context.Request["gcity"]);
                        bcity = HttpUtility.UrlDecode(context.Request["bcity"]);
                        json = GetIMList(sEcho, bcity,gcity, currpage, length, search);
                        break;
                    case "vm":
                        gcity = HttpUtility.UrlDecode(context.Request["city"]);
                        json = GetVMList(sEcho, "", gcity, currpage, length, search);
                        break;
                    case "os":
                        gcity = HttpUtility.UrlDecode(context.Request["city"]);
                        json = GetOSList(sEcho, "", gcity, currpage, length, search);
                        break;
                    case "tbln":
                        json = GetTally(sEcho, "", null, currpage, length, search);
                        break;
                    case "lnbcl":
                        uname = context.Request["uname"];
                        json = GetCustomerList(sEcho, currpage, length, search, gcity, iSortCol_0, sSortDir_0, uname);
                        break;
                    case "lstatus":
                        uname = context.Request["uname"];
                        json = GetLoadStatusList(sEcho, currpage, length, search, gcity, iSortCol_0, sSortDir_0, uname);
                        break;
                    case "cjostatus":
                        uname = context.Request["uname"];
                        json = GetCjoStatusList(sEcho, currpage, length, search, gcity, iSortCol_0, sSortDir_0, uname, context.Request["tname"]);
                        break;
                    case "items":
                        string enddate = context.Request["enddate"];
                         bcity = context.Request["bcity"];;
                        gcity = context.Request["gcity"];;
                        json = GetStorageItems(sEcho,enddate,bcity,gcity,currpage,length);
                        break;
                    default:
                        break;
                }
            }
            context.Response.Write(json);
        }

        /// <summary>
        /// 派车
        /// </summary>
        /// <param name="sEcho"></param>
        /// <param name="bcity"></param>
        /// <param name="gcity"></param>
        /// <param name="currpage"></param>
        /// <param name="length"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public string GetVMList(string sEcho, string bcity, string gcity, int currpage, int length, string search)
        {
            int totalRecord;
            DataTable dt = new DataLib.BLL.VehicleArrange().GetSendCarListStore("", gcity, currpage, length, out totalRecord, search);
            DataTableVehicle dv = new DataTableVehicle();
            dv.sEcho = sEcho;
            dv.iTotalRecords = totalRecord;
            dv.iTotalDisplayRecords = dv.iTotalRecords;


            List<MiniVehicle> list = new List<MiniVehicle>();

            string opurl = "";

            foreach (DataRow dr in dt.Rows)
            {
                MiniVehicle et = new MiniVehicle();
                if (dr["rownum"] != null)
                    et.rownum = Convert.ToInt32(dr["rownum"]);
                if (dr["cjono"] != null)
                    et.cjono = dr["cjono"].ToString();
                if (dr["cum_code"] != null)
                    et.cum_code = dr["cum_code"].ToString();
                if (dr["cum_name"] != null)
                    et.cum_name = dr["cum_name"].ToString();
                if (dr["l_loadnumno"] != null)
                    et.l_loadnumno = dr["l_loadnumno"].ToString();
                if (dr["numberestimate"] != null)
                    et.numberestimate = float.Parse(dr["numberestimate"].ToString());
                if (dr["peculiarrequire"] != null)
                    et.peculiarrequire = dr["peculiarrequire"].ToString();
                if (dr["platenumber"] != null)
                    et.platenumber = dr["platenumber"].ToString();
                if (dr["vaid"] != null)
                {
                    et.vaid = Convert.ToInt32(dr["vaid"]);
                    opurl = string.Format("<a href=\"VehicleArrangeModify.aspx?vaid={0}\">维护</a> &nbsp;&nbsp;<a href=\"VehicleArrangeList.aspx?act=cancle&vaid={0}\">取消</a>", et.vaid);

                }

                if (dr["vehicleNo"] != null)
                    et.vehicleNo = dr["vehicleNo"].ToString();
                if (dr["vehider"] != null)
                    et.vehider = dr["vehider"].ToString();

                et.operatorurl = opurl;

                list.Add(et);

            }
            dv.aaData = list;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(dv);
            return json;
        }

        #region 入库维护
        /// <summary>
        /// 入库维护
        /// </summary>
        /// <param name="sEcho"></param>
        /// <param name="bcity"></param>
        /// <param name="gcity"></param>
        /// <param name="currpage"></param>
        /// <param name="length"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public string GetIMList(string sEcho, string bcity, string gcity, int currpage, int length, string search)
        {
            int totalRecord = 0;
            DataLib.BLL.InStorage bll = new DataLib.BLL.InStorage();
            DataTable dt =bll.GetInsMangeList(bcity,gcity, currpage, length, out totalRecord, search);
            DataTablesModelIm m = new DataTablesModelIm();
            m.sEcho = sEcho;
            m.iTotalRecords = totalRecord;
            m.iTotalDisplayRecords = m.iTotalRecords;
            List<MinsModel> l = new List<MinsModel>();
            foreach (DataRow dr in dt.Rows)
            {
                MinsModel mins = new MinsModel();
                if (dr["rowno"] != null)
                    mins.rowno = int.Parse(dr["rowno"].ToString());
                if (dr["totalnwt"] != null)
                    mins.totalnwt = decimal.Parse(dr["totalnwt"].ToString());
                if (dr["loadnumv"] != null)
                    mins.loadnumv = dr["loadnumv"].ToString();
                if (dr["cjono"] != null)
                    mins.cjono = dr["cjono"].ToString();
                if (dr["bcity"] != null)
                    mins.bcity = dr["bcity"].ToString();
                if (dr["gcity"] != null)
                    mins.gcity = dr["gcity"].ToString();
                if (dr["cumname"] != null)
                    mins.cumname = dr["cumname"].ToString();
                if (dr["wrlno"] != null)
                    mins.wrlno = dr["wrlno"].ToString();
                if (dr["instoragetime"] != null)
                    mins.instoragetime = DateTime.Parse(dr["instoragetime"].ToString()).ToString("yyyy-MM--dd");
                if (dr["rdlcurl"] != null && dr["updateurl"] != null)
                {
                    string html = "<a href='" + dr["updateurl"].ToString() + "'>数据维护</a>";
                    html += "  ";
                    html += "<a href='" + dr["rdlcurl"].ToString() + "'>报表打印</a>";
                    mins.operurl = html;
                }
                l.Add(mins);
            }
            m.aaData = l;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(m);
            return json;

        }
        #endregion



        /// <summary>
        /// 出库维护
        /// </summary>
        /// <param name="sEcho"></param>
        /// <param name="bcity"></param>
        /// <param name="gcity"></param>
        /// <param name="currpage"></param>
        /// <param name="length"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public string GetOSList(string sEcho, string bcity, string gcity, int currpage, int length, string search)
        {
            int totalRecord;
            DataTable dt = new DataLib.BLL.OutStorage().GetOutStorageListStore("", gcity, currpage, length, out totalRecord, search);
            DataTableOutStorage dv = new DataTableOutStorage();
            dv.sEcho = sEcho;
            dv.iTotalRecords = totalRecord;
            dv.iTotalDisplayRecords = dv.iTotalRecords;


            List<MiniOutStorage> list = new List<MiniOutStorage>();

            string opurl = "";

            foreach (DataRow dr in dt.Rows)
            {
                MiniOutStorage et = new MiniOutStorage();
                if (dr["rownum"] != null)
                    et.rownum = Convert.ToInt32(dr["rownum"]);
                if (dr["outStorageNo"] != null)
                    et.outStorageNo = dr["outStorageNo"].ToString();
                if (dr["VLoadNum"] != null)
                    et.VLoadNum = dr["VLoadNum"].ToString();
                if(dr["inDepart"]!=null)
                    et.bcity = dr["inDepart"].ToString();
                if (dr["outDepart"] != null)
                    et.gcity = dr["outDepart"].ToString();
                if (dr["totalWeight"] != null)
                    et.totalWeight = Convert.ToDecimal(dr["totalWeight"]);
                if (dr["outStorageType"] != null)
                    et.outStorageType = SetOutType(dr["outStorageType"].ToString());
                if (dr["status"] != null)
                    et.status = SetStatus(dr["status"].ToString());

                if (dr["id"] != null)
                {
                    et.id = Convert.ToInt32(dr["id"]);
                    opurl = string.Format("<a href=\"/RDLC/OutStorageRDLC.aspx?outStorID={0}\">报表打印</a> &nbsp;&nbsp;<a href=\"/Storage/outStorageUpdate.aspx?outid={0}\">出库维护</a>", et.id);

                }

                et.operatorurl = opurl;

                list.Add(et);

            }
            dv.aaData = list;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(dv);
            return json;
        }

        /// <summary>
        /// 原料理货
        /// </summary>
        /// <param name="sEcho"></param>
        /// <param name="city"></param>
        /// <param name="cumid"></param>
        /// <param name="currpage"></param>
        /// <param name="length"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public string GetTally(string sEcho, string city, string cumid, int currpage, int length, string search)
        {
            int totalRecord;
            DataTable dt = new DataLib.BLL.Tally().GetTallyListByStore(city, cumid, currpage, length, out totalRecord, search);
            DataTableTally dtally = new DataTableTally();
            dtally.sEcho = sEcho;
            dtally.iTotalRecords = totalRecord;
            dtally.iTotalDisplayRecords = dtally.iTotalRecords;

            List<MiniTally> list = new List<MiniTally>();
            foreach (DataRow dr in dt.Rows)
            {
                MiniTally et = new MiniTally();

                if (dr["rownum"] != null)
                    et.rownum = Convert.ToInt32(dr["rownum"]);
                if (dr["loadno"] != null)
                    et.loadno = dr["loadno"].ToString();
                if (dr["colldate_0"] != null)
                    et.colldate_0 = dr["colldate_0"].ToString();
                if (dr["bcity"] != null)
                    et.bcity = dr["bcity"].ToString();
                if (dr["gcity"] != null)
                    et.gcity = dr["gcity"].ToString();
                if (dr["cumstomer"] != null)
                    et.cumstomer = dr["cumstomer"].ToString();
                if (dr["projectcode"] != null)
                    et.projectcode = dr["projectcode"].ToString();
                if (dr["projectname"] != null)
                    et.projectname = dr["projectname"].ToString();
                if (dr["saleman"] != null)
                    et.saleman_str = dr["saleman"].ToString().Replace("@", "-").Replace("/", "-");
                if (dr["totalweight"] != null)
                    et.totalweight = Convert.ToDecimal(dr["totalweight"]);
                if (dr["currNwt"] != null)
                    et.currNwt = Convert.ToDecimal(dr["currNwt"]);
                if (dr["lid"] != null && dr["urltype"] != null)
                {
                    et.lib = Convert.ToInt32(dr["lid"]);

                    if (Convert.ToInt32(dr["urltype"]) == 1)
                    {
                        et.operatorurl =
                            string.Format(
                                "<a href='TallyList.aspx?{0}={1}' >理货列表</a> <br/><a href='Tally.aspx?{0}={1}' >新增理货</a>",
                                "loadid", et.lib);
                    }
                    else
                    {
                        et.operatorurl =
                           string.Format(
                               "<a href='TallyList.aspx?{0}={1}' >理货列表</a> <br/><a href='Tally.aspx?{0}={1}' >新增理货</a>",
                               "outid", Convert.ToInt32(dr["outid"]));
                    }
                }
                list.Add(et);
            }

            dtally.aaData = list;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(dtally);
            return json;
        }

        #region 客户页面
        /// <summary>
        /// 客户页面列表
        /// </summary>
        /// <param name="sEcho"></param>
        /// <param name="currpage"></param>
        /// <param name="length"></param>
        /// <param name="search"></param>
        /// <param name="city"></param>
        /// <param name="order_column"></param>
        /// <param name="order_dir"></param>
        /// <param name="uname"></param>
        /// <returns></returns>
        public string GetCustomerList(string sEcho, int currpage, int length, string search, string city, string order_column, string order_dir, string uname)
        {
            int totalRecord;
            DataLib.BLL.ProjectsRelation bllpr = new DataLib.BLL.ProjectsRelation();
            DataTable dt = null;
            dt = bllpr.GetProjectDetailsByStore("", currpage, length, out totalRecord, search, city, order_column, order_dir, uname);
            DataTableCustomer customer = new DataTableCustomer();
            customer.sEcho = sEcho;
            customer.iTotalRecords = totalRecord;
            customer.iTotalDisplayRecords = customer.iTotalRecords;

            List<MiniCustomer> list = new List<MiniCustomer>();
            int indexnum = 0;
            foreach (DataRow dr in dt.Rows)
            {
                MiniCustomer et = new MiniCustomer();
                indexnum++;
                et.indexnum = indexnum;

                if (dr["pronum"] != null)
                    et.pronum = dr["pronum"].ToString();
                if (dr["proname"] != null)
                    et.proname = dr["proname"].ToString();
                if (dr["cjocolldate"] != null)
                    et.cjocolldate = dr["cjocolldate"].ToString();
                if (dr["loadnum"] != null)
                    et.loadnum = dr["loadnum"].ToString();
                if (dr["cumname"] != null)
                    et.cumname = dr["cumname"].ToString();
                if (dr["addressinfo"] != null)
                    et.addressinfo = dr["addressinfo"].ToString();
                if (dr["cjotruename"] != null)
                    et.cjotruename = dr["cjotruename"].ToString();
                if (dr["totalWeight"] != null)
                    et.totalWeight = Convert.ToDecimal(dr["totalWeight"]);
                if (dr["finishWeight"] != null)
                    et.finishWeight = Convert.ToDecimal(dr["finishWeight"]);
                if (dr["Memo"] != null)
                    et.Memo = dr["Memo"].ToString();
                if (dr["cstatus"] != null)
                    et.cstatus = "<a  style='color:black;' id='a1_" + et.cjoid.ToString() + "'>" + dr["cstatus"].ToString() + "</a>";
                if (dr["cjoid"] != null)
                    et.cjoid = int.Parse(dr["cjoid"].ToString());
                if (dr["l_id"] != null && dr["cumid"] != null)
                {
                    et.operatorurl =
                       string.Format(
                           @"<a href='/Project/AddressByProjectList.aspx?LoadID={0}&cumid={1}'>添加CJO</a> <br/>
                            <a href='CJOByLoadID.aspx?loadid={0}'>CJO列表</a> ",
                           dr["l_id"], dr["cumid"]);
                    if (dr["c_status"] != null)
                    {
                        // string str = "<a style='color:#ccc;'>作废</a>";
                        int tmpstatus = Convert.ToInt32(dr["c_status"]);
                        if (tmpstatus == 1 || tmpstatus == 2)
                        {
                            et.operatorurl += string.Format(@"<span onclick='ZF(this,{0})'><a id='a_" + et.cjoid.ToString() + "' ot='1'  style='color:blue;cursor:pointer;'>作废</a></span>", et.cjoid);
                        }
                        else if (tmpstatus == -9)
                        {
                            et.operatorurl += string.Format(@"<span onclick='ZF(this,{0})'><a id='a_" + et.cjoid.ToString() + "' ot='2' style='color:blue;cursor:pointer;'>撤销作废</a></span>", et.cjoid);
                        }
                        else
                        {
                            et.operatorurl += string.Format(@"<a style='color:#ccc;'>作废</a>", dr["l_id"]);

                        }
                    }
                }

                list.Add(et);
            }

            customer.aaData = list;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(customer);
            return json;
        }

        #endregion




        #region Load进程
        /// <summary>
        /// Load进程
        /// </summary>
        /// <param name="sEcho"></param>
        /// <param name="currpage"></param>
        /// <param name="length"></param>
        /// <param name="search"></param>
        /// <param name="city"></param>
        /// <param name="order_column"></param>
        /// <param name="order_dir"></param>
        /// <param name="uname"></param>
        /// <returns></returns>
        public string GetLoadStatusList(string sEcho, int currpage, int length, string search, string city, string order_column, string order_dir, string uname)
        {
            int totalRecord;
            DataLib.BLL.CJOItem bllcitem = new DataLib.BLL.CJOItem();
            DataTable dt = null;
            dt = bllcitem.GetLoadStatusList("", currpage, length, out totalRecord, search, city, order_column, order_dir, uname);
            DataTableLoadStatus customer = new DataTableLoadStatus();
            customer.sEcho = sEcho;
            customer.iTotalRecords = totalRecord;
            customer.iTotalDisplayRecords = customer.iTotalRecords;

            List<LoadStatus> list = new List<LoadStatus>();
            int indexnum = 0;
            foreach (DataRow dr in dt.Rows)
            {
                LoadStatus et = new LoadStatus();
                indexnum++;
                et.indexnum = indexnum;

                if (dr["indexnum"] != null)
                    et.indexnum = int.Parse(dr["indexnum"].ToString());
                if (dr["l_loadnumno"] != null)
                    et.l_loadnumno = dr["l_loadnumno"].ToString();
                if (dr["c_cjonno"] != null)
                    et.c_cjonno = dr["c_cjonno"].ToString();
                if (dr["cum_code"] != null)
                    et.cum_code = dr["cum_code"].ToString();
                if (dr["cum_name"] != null)
                    et.cum_name = dr["cum_name"].ToString();
                if (dr["v_numberestimate"] != null)
                    et.v_numberestimate = dr["v_numberestimate"].ToString();
                if (dr["v_peculiarrequire"] != null)
                    et.v_peculiarrequire = dr["v_peculiarrequire"].ToString();
                if (dr["v_workcount"] != null)
                    et.v_workcount = dr["v_workcount"].ToString();

                if (dr["cjoid"] != null)
                    et.cjoid = int.Parse(dr["cjoid"].ToString());
                if (dr["authname"] != null)
                    et.authname = dr["authname"].ToString();
                string agree = "<a style='color:#ccc;'>批准撤销</a>";

                if (dr["c_status"] != null)
                {
                    int c_status = int.Parse(dr["c_status"].ToString());
                    et.cjoagree = agree;
                    switch (c_status)
                    {
                        case 1:
                            et.cjostatus = "待派车";
                            break;
                        case 2:
                            et.cjostatus = "待称重";
                            break;
                        case 3:
                            et.cjostatus = "待授权";
                            break;
                        case 4:
                            {
                                et.cjostatus = GetCjoid(et.cjoid.ToString());
                                break;
                            }
                        case 5:
                            {
                                et.cjostatus = "拆解中";
                                break;
                            }
                        case -4:
                            et.cjostatus = "拆解申请审批中";
                            et.cjoagree = "<span onclick='CXSQ(this," + et.cjoid.ToString() + ")'><a style='color:blue;'>批准撤销</a></span>";
                            break;
                        case -9:
                            et.cjostatus = "作废";
                            break;
                        case -1:
                            et.cjostatus = "退运";
                            break;
                        case -2:
                            et.cjostatus = "直销";
                            break;
                        default:
                            break;

                    }

                }

                list.Add(et);
            }

            customer.aaData = list;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(customer);
            return json;
        }
        #endregion

        #region 待授权
        /// <summary>
        /// 待授权
        /// </summary>
        /// <param name="sEcho"></param>
        /// <param name="currpage"></param>
        /// <param name="length"></param>
        /// <param name="search"></param>
        /// <param name="city"></param>
        /// <param name="order_column"></param>
        /// <param name="order_dir"></param>
        /// <param name="uname"></param>
        /// <returns></returns>
        public string GetCjoStatusList(string sEcho, int currpage, int length, string search, string city, string order_column, string order_dir, string uname,string tname)
        {
            int totalRecord;
            DataLib.BLL.CJOItem bllcitem = new DataLib.BLL.CJOItem();
            DataTable dt = null;
            dt = bllcitem.getAuthList(currpage, length, out totalRecord, search, city, order_column, order_dir, uname);
            DataTableAuth tauth = new DataTableAuth();
            tauth.sEcho = sEcho;
            tauth.iTotalRecords = totalRecord;
            tauth.iTotalDisplayRecords = tauth.iTotalRecords;

            List<CjoAuth> list = new List<CjoAuth>();
            int indexnum = 0;
            foreach (DataRow dr in dt.Rows)
            {
                CjoAuth et = new CjoAuth();
                indexnum++;
                et.indexnum = indexnum;

                if (dr["indexnum"] != null)
                    et.indexnum = int.Parse(dr["indexnum"].ToString());
                if (dr["loadnum"] != null)
                    et.loadnum = dr["loadnum"].ToString();
                if (dr["cjono"] != null)
                    et.cjono = dr["cjono"].ToString();
                if (dr["cumcode"] != null)
                    et.cumcode = dr["cumcode"].ToString();
                if (dr["cumname"] != null)
                    et.cumname = dr["cumname"].ToString();
                if (dr["numberestimate"] != null)
                    et.numberestimate = dr["numberestimate"].ToString();
                if (dr["peculiarrequire"] != null)
                    et.peculiarrequire = dr["peculiarrequire"].ToString();

                if (dr["cjoid"] != null)
                    et.cjoid = int.Parse(dr["cjoid"].ToString());

                string agree1 = "<span><a onclick='Auth(this," + et.cjoid.ToString() +  ")' style='color:blue;' title='授权拆解'>授权</a><a title='授权撤销申请' style='color:#ccc;'>撤销申请</a><span>";
                string agree2 = "<span><a style='color:ccc;' title='授权拆解'>授权</a><a title='授权撤销申请'onclick='AuthCancel(this," + et.cjoid.ToString() + ")' style='color:blue;'>撤销申请</a><span>";
                string agree3 = "<span><a style='color:ccc;' title='授权拆解'>授权</a><a title='授权撤销申请' style='color:#ccc;'>撤销申请</a><span>";
                
                if (dr["cjostatus"] != null)
                {
                    int cjostatus = int.Parse(dr["cjostatus"].ToString());
                    DataLib.Model.Cjo model = new DataLib.Model.Cjo();
                    DataLib.BLL.Cjo bll = new DataLib.BLL.Cjo();
                    DataLib.Model.CJOItem cmodel = new DataLib.Model.CJOItem();
                    DataLib.BLL.CJOItem b = new DataLib.BLL.CJOItem();
                    cmodel = b.GetListByCid(et.cjoid);
                    model = bll.GetModel(et.cjoid);
                    if (model != null)
                    {
                        if (uname == model.sealman_auth || uname=="admin" || tname == model.sealman_auth || tname==cmodel.cjopowertruename || uname == cmodel.cjopowerusername)
                        {
                            
                            if (cjostatus == 3)
                                et.cjoagree = agree1;
                            else
                                et.cjoagree = agree2;
                        }
                        else
                        {
                            et.cjoagree = agree3;
                        }
                    }
                    else
                    {
                        
                        et.cjoagree = agree3;
                    }
                    switch (cjostatus)
                    {
                        case 1:
                            et.cjostatus = "待派车";
                            break;
                        case 2:
                            et.cjostatus = "待称重";
                            break;
                        case 3:
                            et.cjostatus = "待授权";
                            break;
                        case 4:
                            {
                                et.cjostatus = GetCjoid(et.cjoid.ToString());
                                break;
                            }
                        case 5:
                            {
                                et.cjostatus = "拆解中";
                                break;
                            }
                        case -4:
                            et.cjostatus = "拆解申请审批中";
                            et.cjoagree = "<span onclick='CXSQ(this," + et.cjoid.ToString() + ")'><a style='color:blue;'>批准撤销</a></span>";
                            break;
                        case -9:
                            et.cjostatus = "作废";
                            break;
                        case -1:
                            et.cjostatus = "退运";
                            break;
                        case -2:
                            et.cjostatus = "直销";
                            break;
                        default:
                            break;

                    }
                }

                list.Add(et);
            }

            tauth.aaData = list;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(tauth);
            return json;
        }
        #endregion


        #region 库存明细
        /// <summary>
        /// 库存明细
        /// </summary>
        /// <param name="sEcho"></param>
        /// <param name="city"></param>
        /// <param name="currpage"></param>
        /// <param name="length"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public string GetStorageItems(string sEcho, string enddate, string bcity, string gcity, int currpage, int length)
        {
            int totalRecord;
            DataLib.BLL.StorageData bll = new DataLib.BLL.StorageData();
            DataTable dt = bll.StorageItemsQueryPage(enddate,bcity,gcity,currpage,length,out totalRecord);
            DataTablesModelItems m = new DataTablesModelItems();
            m.sEcho = sEcho;
            m.iTotalRecords = totalRecord;
            m.iTotalDisplayRecords = m.iTotalRecords;
            List<QueryItems> l = new List<QueryItems>();
        //      private int _rowno;
        //private string _bcity;
        //private string _gcity;
        //private string _projectcode;
        //private string _projectname;
        //private string _load;
        //private string _cumname;
        //private string _cumshortname;
        //private string _bussCode;
        //private decimal _gwt;
        //private decimal _tare1;
        //private decimal _tare2;
        //private decimal _nwt;
        //private string _rubcode;
        //private string _rubname;
        //private string _boxno;
        //private string _barcodevalue;
        //private string _insdate;
        //private string _SType;
        //private string _clearingmonth;
        //private string _lockstatus;
            foreach (DataRow dr in dt.Rows)
            {
                QueryItems mins = new QueryItems();
                if (dr["rowno"] != null)
                    mins.rowno = int.Parse(dr["rowno"].ToString());
                if (dr["bcity"] != null)
                    mins.bcity = dr["bcity"].ToString();
                if (dr["gcity"] != null)
                    mins.gcity = dr["gcity"].ToString();
                if (dr["projectcode"] != null)
                    mins.projectcode = dr["projectcode"].ToString();
                if (dr["projectname"] != null)
                    mins.projectname = dr["projectname"].ToString();
                if (dr["load"] != null)
                    mins.load = dr["load"].ToString();
                if (dr["cumname"] != null)
                    mins.cumname = dr["cumname"].ToString();
                if (dr["cumshortname"] != null)
                    mins.cumshortname = dr["cumshortname"].ToString();
                if (dr["bussCode"] != null)
                    mins.bussCode = dr["bussCode"].ToString();
                if (dr["gwt"] != null)
                    mins.gwt = decimal.Parse(dr["gwt"].ToString());
                if (dr["tare1"] != null)
                    mins.tare1 = decimal.Parse(dr["tare1"].ToString());
                if (dr["tare2"] != null)
                    mins.tare2 = decimal.Parse(dr["tare2"].ToString());
                if (dr["nwt"] != null)
                    mins.nwt = decimal.Parse(dr["nwt"].ToString());
                if (dr["rubcode"] != null)
                    mins.rubcode = dr["rubcode"].ToString();
                if (dr["rubname"] != null)
                    mins.rubname = dr["rubname"].ToString();
                if (dr["boxno"] != null)
                    mins.boxno = dr["boxno"].ToString();
                if (dr["barcodevalue"] != null)
                    mins.barcodevalue = dr["barcodevalue"].ToString();
                if (dr["insdate"] != null)
                    mins.insdate = dr["insdate"].ToString();
                if (dr["SType"] != null)
                    mins.SType = dr["SType"].ToString();
                if (dr["clearingmonth"] != null)
                    mins.clearingmonth = dr["clearingmonth"].ToString();
                if (dr["lockstatus"] != null)
                    mins.lockstatus = dr["lockstatus"].ToString();
                if (dr["goodscode"] != null)
                    mins.goodscode = dr["goodscode"].ToString();
                if (dr["goodsname"] != null)
                    mins.goodsname = dr["goodsname"].ToString();
              
                l.Add(mins);
            }
            m.aaData = l;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(m);
            return json;

        }
        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private string SetOutType(string outtype)
        {
            string str = "";
            switch (outtype)
            {
                case "1":
                    str = "出库拆解";
                    break;
                case "2":
                    str = "出库分类";
                    break;
                case "3":
                    str = "出库生产";
                    break;
                case "4":
                    str = "出库销售";
                    break;
                case "5":
                    str = "移库出库";
                    break;
                default:
                    break;
            }
            return str;
        }

        /// <summary>
        /// 取分类状态
        /// </summary>
        /// <param name="cjoid"></param>
        /// <returns></returns>
        private string GetCjoid(string cjoid)
        {
            string flag = "";
            DataLib.Model.Cjo cmodel = new DataLib.BLL.Cjo().GetModel(int.Parse(cjoid));
            if (cmodel != null)
            {
                DataLib.Model.LoadNum lModel = new DataLib.BLL.LoadNum().GetModel(cmodel.loadnumid);
                if (lModel != null)
                {
                    if (lModel.finishWeight == 0)
                    {
                        flag = "待分类";       //待分类
                    }
                    else if (lModel.finishWeight < lModel.totalWeight)
                    {
                        flag = "分类中";       //分类中
                    }
                    else
                    {
                        flag = "分类完成";       //分类完成
                    }
                }
            }
            return flag;
        }


        private string SetStatus(string status)
        {
            string str = "";
            if (status == "0")
            {
                str = "入库完成";
            }
            else
            {
                str = "待入库";
            }
            return str;
        }


    }

    #region 入库维护 Model

    [Serializable]
    public class MinsModel
    {
        private int _rowno;
        private string _loadnumv;
        private string _wrlno;
        private string _cumname;
        private decimal _totalnwt;
        private string _instoragetime;
        private string _operurl;
        private string _cjono;
        private string _bcity;
        private string _gcity;

        /// <summary>
        /// 行号
        /// </summary>
        public int rowno
        {
            get { return _rowno; }
            set { _rowno = value; }
        }

        /// <summary>
        /// 虚拟load
        /// </summary>
        public string loadnumv
        {
            get { return _loadnumv; }
            set { _loadnumv = value; }
        }

        /// <summary>
        /// cjo号
        /// </summary>
        public string cjono
        {
            get { return _cjono; }
            set { _cjono = value; }
        }


        /// <summary>
        /// 入库单号
        /// </summary>
        public string wrlno
        {
            get { return _wrlno; }
            set { _wrlno = value; }
        }


        /// <summary>
        /// 归属地
        /// </summary>
        public string bcity
        {
            get { return _bcity; }
            set { _bcity = value; }
        }



        /// <summary>
        /// 处理地
        /// </summary>
        public string gcity
        {
            get { return _gcity; }
            set { _gcity = value; }
        }

        /// <summary>
        /// 客户名称
        /// </summary>
        public string cumname
        {
            get { return _cumname; }
            set { _cumname = value; }
        }

        /// <summary>
        /// 入库总重量
        /// </summary>
        public decimal totalnwt
        {
            get { return _totalnwt; }
            set { _totalnwt = value; }
        }

        /// <summary>
        /// 入库时间
        /// </summary>
        public string instoragetime
        {
            get { return _instoragetime; }
            set { _instoragetime = value; }
        }

        /// <summary>
        /// 操作URL
        /// </summary>
        public string operurl
        {
            get { return _operurl; }
            set { _operurl = value; }
        }
    }


    [Serializable]
    public class DataTablesModelIm
    {
        private string _sEcho;
        private int _iTotalRecords;
        private List<MinsModel> _aaData;
        private int _iTotalDisplayRecords;

        /// <summary>
        /// 行号
        /// </summary>
        public string sEcho
        {
            get { return _sEcho; }
            set { _sEcho = value; }
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int iTotalRecords
        {
            get { return _iTotalRecords; }
            set { _iTotalRecords = value; }
        }

        /// <summary>
        /// 过滤后的总记录数
        /// </summary>
        public int iTotalDisplayRecords
        {
            get { return _iTotalDisplayRecords; }
            set { _iTotalDisplayRecords = value; }
        }


        //数据集
        public List<MinsModel> aaData
        {
            get { return _aaData; }
            set { _aaData = value; }
        }
    }
    #endregion

    #region 派车Model
    [Serializable]
    public class MiniVehicle
    {
        public int rownum { get; set; }
        public string l_loadnumno { get; set; }
        public string cjono { get; set; }
        public string cum_code { get; set; }
        public string cum_name { get; set; }
        public string vehicleNo { get; set; }
        public string vehider { get; set; }
        public string platenumber { get; set; }
        public int vaid { get; set; }
        public float numberestimate { get; set; }
        public string peculiarrequire { get; set; }
        public string operatorurl { get; set; }
    }

    [Serializable]
    public class DataTableVehicle
    {
        private string _sEcho;
        private int _iTotalRecords;
        private List<MinsModel> _aaData;
        private int _iTotalDisplayRecords;

        /// <summary>
        /// 行号
        /// </summary>
        public string sEcho
        {
            get { return _sEcho; }
            set { _sEcho = value; }
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int iTotalRecords { get; set; }

        /// <summary>
        /// 过滤后的总记录数
        /// </summary>
        public int iTotalDisplayRecords { get; set; }


        //数据集
        public List<MiniVehicle> aaData { get; set; }
    }
    #endregion

    #region 出库维护列表
    [Serializable]
    public class MiniOutStorage
    {
        public int rownum { get; set; }
        public int id { get; set; }
        public string outStorageNo { get; set; }
        public string VLoadNum { get; set; }
        public decimal totalWeight { get; set; }
        public string outStorageType { get; set; }
        public string status { get; set; }
        public string operatorurl { get; set; }
        public string bcity { get; set; }
        public string gcity { get; set; }
    }
    [Serializable]
    public class DataTableOutStorage
    {
        private string _sEcho;
        private int _iTotalRecords;
        private List<MiniOutStorage> _aaData;
        private int _iTotalDisplayRecords;

        /// <summary>
        /// 行号
        /// </summary>
        public string sEcho
        {
            get { return _sEcho; }
            set { _sEcho = value; }
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int iTotalRecords { get; set; }

        /// <summary>
        /// 过滤后的总记录数
        /// </summary>
        public int iTotalDisplayRecords { get; set; }


        //数据集
        public List<MiniOutStorage> aaData { get; set; }

    }
    #endregion

    #region 原料理货
    [Serializable]
    public class MiniTally
    {
        public int rownum { get; set; }
        public int lib { get; set; }
        public int urltype { get; set; }
        public string loadno { get; set; }
        public string bcity { get; set; }
        public string gcity { get; set; }
        public string colldate_0 { get; set; }
        public string cumstomer { get; set; }
        public string projectcode { get; set; }
        public string projectname { get; set; }
        public string saleman_str { get; set; }
        public decimal totalweight { get; set; }
        public decimal currNwt { get; set; }
        public string operatorurl { get; set; }
    }

    [Serializable]
    public class DataTableTally
    {
        private string _sEcho;
        private int _iTotalRecords;
        private List<MiniTally> _aaData;
        private int _iTotalDisplayRecords;

        /// <summary>
        /// 行号
        /// </summary>
        public string sEcho
        {
            get { return _sEcho; }
            set { _sEcho = value; }
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int iTotalRecords { get; set; }

        /// <summary>
        /// 过滤后的总记录数
        /// </summary>
        public int iTotalDisplayRecords { get; set; }


        //数据集
        public List<MiniTally> aaData { get; set; }

    }
    #endregion

    #region Load列表

    /// <summary>
    /// Load列表
    /// </summary>
    [Serializable]
    public class MiniCustomer
    {
        public int indexnum { get; set; }
        public string pronum { get; set; }
        public string proname { get; set; }
        public string cjocolldate { get; set; }
        public string loadnum { get; set; }
        public string cumname { get; set; }
        public string addressinfo { get; set; }
        public string cjotruename { get; set; }
        public decimal totalWeight { get; set; }
        public decimal finishWeight { get; set; }
        public string Memo { get; set; }
        public string cstatus { get; set; }
        public int cjoid { get; set; }
        public string operatorurl { get; set; }

    }


    [Serializable]
    public class DataTableCustomer
    {
        private string _sEcho;
        private int _iTotalRecords;
        private List<MiniCustomer> _aaData;
        private int _iTotalDisplayRecords;

        /// <summary>
        /// 行号
        /// </summary>
        public string sEcho
        {
            get { return _sEcho; }
            set { _sEcho = value; }
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int iTotalRecords { get; set; }

        /// <summary>
        /// 过滤后的总记录数
        /// </summary>
        public int iTotalDisplayRecords { get; set; }


        //数据集
        public List<MiniCustomer> aaData { get; set; }

    }
    #endregion

    #region Load进程
    /// <summary>
    /// Load进程
    /// </summary>
    [Serializable]
    public class LoadStatus
    {
        public int indexnum { get; set; }
        public string l_loadnumno { get; set; }
        public string c_cjonno { get; set; }
        public string cum_code { get; set; }
        public string cum_name { get; set; }
        public string v_numberestimate { get; set; }
        public string v_peculiarrequire { get; set; }
        public string v_workcount { get; set; }
        public int c_status { get; set; }
        public int cjoid { get; set; }
        public string cjostatus { get; set; }
        public string cjoagree { get; set; }
        public string authname { get; set; }

    }

    [Serializable]
    public class DataTableLoadStatus
    {
        private string _sEcho;
        private int _iTotalRecords;
        private List<MiniCustomer> _aaData;
        private int _iTotalDisplayRecords;

        /// <summary>
        /// 行号
        /// </summary>
        public string sEcho
        {
            get { return _sEcho; }
            set { _sEcho = value; }
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int iTotalRecords { get; set; }

        /// <summary>
        /// 过滤后的总记录数
        /// </summary>
        public int iTotalDisplayRecords { get; set; }


        //数据集
        public List<LoadStatus> aaData { get; set; }

    }
    #endregion

    #region 库存明细
    [Serializable]
    public class QueryItems
    {
        private int _rowno;
        private string _bcity;
        private string _gcity;
        private string _projectcode;
        private string _projectname;
        private string _load;
        private string _cumname;
        private string _cumshortname;
        private string _bussCode;
        private decimal _gwt;
        private decimal _tare1;
        private decimal _tare2;
        private decimal _nwt;
        private string _rubcode;
        private string _rubname;
        private string _boxno;
        private string _barcodevalue;
        private string _insdate;
        private string _SType;
        private string _clearingmonth;
        private string _lockstatus;
        private string _goodsname;
        private string _goodscode;


        /// <summary>
        /// 行号
        /// </summary>
        public int rowno
        {
            get { return _rowno; }
            set { _rowno = value; }
        }

        /// <summary>
        /// 归属地
        /// </summary>
        public string bcity
        {
            get { return _bcity; }
            set { _bcity = value; }
        }
        /// <summary>
        /// 处理地
        /// </summary>
        public string gcity
        {
            get { return _gcity; }
            set { _gcity = value; }
        }
        /// <summary>
        /// 项目编号
        /// </summary>
        public string projectcode
        {
            get { return _projectcode; }
            set { _projectcode = value; }
        }
        /// <summary>
        /// 项目名称
        /// </summary>
        public string projectname
        {
            get { return _projectname; }
            set { _projectname = value; }
        }
        /// <summary>
        /// Load号
        /// </summary>
        public string load
        {
            get { return _load; }
            set { _load = value; }
        }
        /// <summary>
        /// 客户
        /// </summary>
        public string cumname
        {
            get { return _cumname; }
            set { _cumname = value; }
        }
        /// <summary>
        /// 客户简称
        /// </summary>
        public string cumshortname
        {
            get { return _cumshortname; }
            set { _cumshortname = value; }
        }
        /// <summary>
        /// 财务编码
        /// </summary>
        public string bussCode
        {
            get { return _bussCode; }
            set { _bussCode = value; }
        }
        /// <summary>
        /// 毛重
        /// </summary>
        public decimal gwt
        {
            get { return _gwt; }
            set { _gwt = value; }
        }
        /// <summary>
        /// 皮1
        /// </summary>
        public decimal tare1
        {
            get { return _tare1; }
            set { _tare1 = value; }
        }
        /// <summary>
        /// 皮2
        /// </summary>
        public decimal tare2
        {
            get { return _tare2; }
            set { _tare2 = value; }
        }
        /// <summary>
        /// 净重
        /// </summary>
        public decimal nwt
        {
            get { return _nwt; }
            set { _nwt = value; }
        }

        /// <summary>
        /// 废物编码
        /// </summary>
        public string rubcode
        {
            get { return _rubcode; }
            set { _rubcode = value; }
        }
        /// <summary>
        /// 废物名称
        /// </summary>
        public string rubname
        {
            get { return _rubname; }
            set { _rubname = value; }
        }
        /// <summary>
        /// 箱号
        /// </summary>
        public string boxno
        {
            get { return _boxno; }
            set { _boxno = value; }
        }

        /// <summary>
        /// 入库日期
        /// </summary>
        public string insdate
        {
            get { return _insdate; }
            set { _insdate = value; }
        }
        
        /// <summary>
        /// 条码
        /// </summary>
        public string barcodevalue
        {
            get { return _barcodevalue; }
            set { _barcodevalue = value; }
        }
        /// <summary>
        /// 库存类型
        /// </summary>
        public string SType
        {
            get { return _SType; }
            set { _SType = value; }
        }
        /// <summary>
        /// 结算月
        /// </summary>
        public string clearingmonth
        {
            get { return _clearingmonth; }
            set { _clearingmonth = value; }
        }
        /// <summary>
        /// 锁定状态
        /// </summary>
        public string lockstatus
        {
            get { return _lockstatus; }
            set { _lockstatus = value; }
        }

        /// <summary>
        /// 物品编码
        /// </summary>
        public string goodscode
        {
            get { return _goodscode; }
            set { _goodscode = value; }
        }

        /// <summary>
        /// 物品名称
        /// </summary>
        public string goodsname
        {
            get { return _goodsname; }
            set { _goodsname = value; }
        }


        
    }


    [Serializable]
    public class DataTablesModelItems
    {
        private string _sEcho;
        private int _iTotalRecords;
        private List<QueryItems> _aaData;
        private int _iTotalDisplayRecords;

        /// <summary>
        /// 行号
        /// </summary>
        public string sEcho
        {
            get { return _sEcho; }
            set { _sEcho = value; }
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int iTotalRecords
        {
            get { return _iTotalRecords; }
            set { _iTotalRecords = value; }
        }

        /// <summary>
        /// 过滤后的总记录数
        /// </summary>
        public int iTotalDisplayRecords
        {
            get { return _iTotalDisplayRecords; }
            set { _iTotalDisplayRecords = value; }
        }


        //数据集
        public List<QueryItems> aaData
        {
            get { return _aaData; }
            set { _aaData = value; }
        }
    }
    #endregion

    #region 待授权
    /// <summary>
    /// Load进程
    /// </summary>
    [Serializable]
    public class CjoAuth
    {
        public int indexnum { get; set; }
        public string loadnum { get; set; }
        public string cjono { get; set; }
        public string cumcode { get; set; }
        public string cumname { get; set; }
        public string numberestimate { get; set; }
        public string peculiarrequire { get; set; }
        public int cjoid { get; set; }
        public string cjostatus { get; set; }
        public string cjoagree { get; set; }

    }

    [Serializable]
    public class DataTableAuth
    {
        private string _sEcho;
        private int _iTotalRecords;
        private List<CjoAuth> _aaData;
        private int _iTotalDisplayRecords;

        /// <summary>
        /// 行号
        /// </summary>
        public string sEcho
        {
            get { return _sEcho; }
            set { _sEcho = value; }
        }

        /// <summary>
        /// 总记录数
        /// </summary>
        public int iTotalRecords { get; set; }

        /// <summary>
        /// 过滤后的总记录数
        /// </summary>
        public int iTotalDisplayRecords { get; set; }


        //数据集
        public List<CjoAuth> aaData { get; set; }

    }
    #endregion

}